﻿@{
    ViewBag.Title = "部门管理";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}

<script language="javascript" type="text/javascript">
    //添加部门
    function addDep() {
        InitDepCombobox();
        $('#dlg').dialog('open').dialog('setTitle', '新增');
        $('#fm').form('clear');
        url = '/BasicManage/AddDep';
    }

    //编辑部门树
    function editDep() {
        var row = $('#tt').tree('getSelected');
        if (row) {
            InitDepCombobox(row.id);
            $('#dlg').dialog('open').dialog('setTitle', '编辑');
            $.post("/BasicManage/GetDepModel", { id: row.id }, function (json) {
                $('#fm').form('load', json);
                url = "/BasicManage/EditDep";
            });
        }
    }


    //删除部门
    function delDep() {
        var row = $('#tt').tree('getSelected');
        if (row) {
            $.messager.confirm('提示信息', '数据删除之后无法恢复,你确定要删除吗?', function (r) {
                if (r) {
                    $.post('/BasicManage/DelDep', { id: row.id }, function (json) {
                        Helper.Show(json.Msg);
                        if (json.Code == 1) {
                            $('#tt').tree('reload'); // reload the user data
                        }
                    });
                }
            });
        }
    }

    //保存Tree
    function SaveDep() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Success) {
                    $('#dlg').dialog('close'); 	// 关闭弹出层
                    $('#tt').tree('reload'); // reload the user data
                }
            }
        });
    }

    //初始化部门列表
    function InitDepCombobox(id) {
        if (id == undefined) id = 0;
        $('#ParentId').combobox({
            url: InitUrl.Dep + "?id=" + id,
            valueField: 'Id',
            textField: 'DepName',
            method: 'post'
        });
    }
</script>
<div id="tb" style="padding: 3px; height: auto; border: 1px solid #red; background-color: #00000;">
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addDep()">添加</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editDep()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-cut" plain="true" onclick="delDep()">删除</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" title="弹出页面" data-options="iconCls:'icon-save'"
     closed="true" style="width: 400px; height: 280px; padding: 10px 20px" buttons="#dlg-buttons" modal="true">
    <div class="ftitle">
    </div>
    <form id="fm" method="post" novalidate>
        <input type="hidden" name="Id" />
        <div class="fitem">
            <label>
                所属上级:
            </label>
            <input id="ParentId" name="ParentId" class="easyui-combobox" required="true" style="width: 173px; height: 30px;" />
        </div>
        <div class="fitem">
            <label>
                部门名称:
            </label>
            <input name="DepName" id="DepName" class="easyui-validatebox textbox" required="true" style="width: 173px; height: 30px;" autocomplete="off" />
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="SaveDep()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
<div class="demo-info">
    <div class="demo-tip icon-tip">
    </div>
    <div>
    </div>
</div>
<div style="margin: 10px 0;">
</div>
<ul id="tt" class="easyui-tree" data-options="url:'/BasicManage/InitDepTree',method:'post',animate:true,lines:true ">
</ul>
